<template>
    <div>
        旧密码
        <input type="text" v-model="oldpwd">
        新密码
        <input type="text" v-model="newpwd">
        <p>{{msg}}</p>
        <Button :loading="isShowLoading" class="submit" type="primary" @click="submit">修改</Button>
    </div>
</template>

<script>
export default {
    name: 'password',
    data() {
        return {
            oldpwd: '',
            newpwd: '',
            isShowLoading: false,
            msg: '',
        }
    },
    methods: {
        submit() {
            let userName = localStorage.getItem('userName')
            fetch('http://localhost:5000/changepassword', {
                method: 'post',
                body: JSON.stringify({
                    username: userName,
                    oldpassword: this.oldpwd,
                    newpassword: this.newpwd,
                }),
                headers: { 'Content-Type': 'application/json' },
            }).then(
                (res) => res.json()
            ).then(
                (res) => {
                    this.msg = res.result
                }
            )
        },
    },
}
</script>

<style scoped>

</style>
